clear
load tsp_data


tempindex = find(year >1970 & year < 1987);
tsp = tsp(tempindex);
year = year(tempindex);


figure(1)
[f,xi,bw] = ksdensity(tsp,linspace(0,150,100),'bandwidth',1.25);
%[f,xi,bw] = ksdensity(tsp);
plot(xi,f,'black','lineWidth',1.5)
xlabel('TSP','FontSize',16), ylabel('Density','FontSize',16)
%xlim([-2 6])
myfiguresize = [0, 1, 8.5, 5.0];
set(gcf, 'PaperPosition', myfiguresize);
print -dpng tspden -r200

num_year = length(unique(year));
meantsp = zeros(num_year,1);
for t = 1:num_year
    meantsp(t) = mean(tsp(year==t+min(year)-1));
end
annum = [1:1:num_year]' + min(year)-1;

figure(2)
plot(annum,meantsp,'black','linewidth', 1.5)
xlabel('Year','FontSize',16), ylabel('TSP','FontSize',16)
h = gca;
xlim([min(annum)-1 max(annum)+1])
myfiguresize = [0, 1, 8.5, 5.0];
set(gcf, 'PaperPosition', myfiguresize);
print -dpng tsp_overtime -r200